package com.disruptor.demo.controller;

import com.disruptor.demo.event.TradeEvent;
import com.disruptor.demo.model.DataResponseVo;
import com.disruptor.demo.model.SeriesData;
import com.disruptor.demo.model.TestData;
import com.disruptor.demo.queue.SeriesDataEventQueueHelper;
import com.disruptor.demo.queue.TestDataEventQueueHelper;
import com.disruptor.demo.util.ThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author <a href="mailto:18335553083@163.com">Mr_He</a>
 * @Copyright (c)</   b> HeC<br/>
 * @createTime 2018/8/2 8:32
 * @Description:
 */
@RestController
public class TestController {

    private Logger logger = LoggerFactory.getLogger(TestController.class);

    /**
     * 注入消息生产者
     */
    @Autowired
    private SeriesDataEventQueueHelper seriesDataEventQueueHelper;

    @Autowired
    private TestDataEventQueueHelper testDataEventQueueHelper;


    @RequestMapping(value = "/data")
    @ResponseBody
    public DataResponseVo<String> receiverDeviceData(Integer deviceData, Integer type) {
        long startTime1 = System.currentTimeMillis();

        TradeEvent tradeEvent = new TradeEvent(testDataEventQueueHelper, seriesDataEventQueueHelper, type, deviceData);
        ThreadPool.exe(tradeEvent);

        logger.info("入队列完成");
        long startTime2 = System.currentTimeMillis();
        logger.info("receiver data ==[{}] millisecond ==[{}]", deviceData, startTime2 - startTime1);
        return new DataResponseVo<String>(200, "success");
    }



}
